import IconEth from "@/assets/chain/eth.svg";
import IconBNB from "@/assets/chain/bnb.svg";
import IconOKC from "@/assets/chain/okc.svg";
import IconMetis from "@/assets/chain/metis.svg";
import IconFantom from "@/assets/chain/fantom.svg";
import IconHeco from "@/assets/chain/heco.svg";
import IconPolygon from "@/assets/chain/polygon.svg";
import IconGnosis from "@/assets/chain/gnosis.svg";
import IconAvalanche from "@/assets/chain/avalanche.svg";
import IconHarmony from "@/assets/chain/harmony.svg";
import IconArbitrum from "@/assets/chain/arbitrum.svg";
import IconOptimism from "@/assets/chain/optimism.svg";
import IconBOBA from "@/assets/chain/boba.svg";
import IconMoonriver from "@/assets/chain/moonriver.svg";
import IconAurora from "@/assets/chain/aurora.svg";
import IconCronos from "@/assets/chain/cronos.svg";
import IconKava from "@/assets/chain/kava.svg";
import IconCelo from "@/assets/chain/celo.svg";
import IconKlaytn from "@/assets/chain/klaytn.svg";
import IconZkSync from "@/assets/chain/zksync.svg";
import TokenList from "@/config/token.json";

export const ChainList = [
  {
    chainName: "Ethereum",
    chainCode: "ethereum",
    chainId: 1,
    chainIcon: IconEth,
    txExplorerUrl: "https://etherscan.io/tx/",
    blockExplorerUrls: ["https://etherscan.io/"],
    rpcUrls: ["https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"],
    defaultSymbol: {
      in: "ETH",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Ethereum",
      symbol: "ETH",
    },
    disabled: false,
  },
  {
    chainName: "BNB Chain",
    chainCode: "bsc",
    chainId: 56,
    chainIcon: IconBNB,
    txExplorerUrl: "https://bscscan.com/tx/",
    blockExplorerUrls: ["https://bscscan.com/"],
    rpcUrls: ["https://bsc-dataseed1.binance.org/"],
    defaultSymbol: {
      in: "BNB",
      out: "BUSD",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Binance",
      symbol: "BNB",
    },
    disabled: false,
  },
  {
    chainName: "Arbitrum",
    chainCode: "arbitrum",
    chainId: 42161,
    chainIcon: IconArbitrum,
    txExplorerUrl: "https://arbiscan.io/tx/",
    blockExplorerUrls: ["https://arbiscan.io/"],
    rpcUrls: ["https://arb1.arbitrum.io/rpc"],
    defaultSymbol: {
      in: "UNI",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Ethereum",
      symbol: "ETH",
    },
    disabled: false,
  },
  {
    chainName: "Optimism",
    chainCode: "optimism",
    chainId: 10,
    chainIcon: IconOptimism,
    txExplorerUrl: "https://optimistic.etherscan.io/tx/",
    blockExplorerUrls: ["https://optimistic.etherscan.io/"],
    rpcUrls: ["https://rpc.ankr.com/optimism"],
    defaultSymbol: {
      in: "ETH",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Ethereum",
      symbol: "ETH",
    },
    disabled: false,
  },
  {
    chainName: "Avalanche",
    chainCode: "avax",
    chainId: 43114,
    chainIcon: IconAvalanche,
    txExplorerUrl: "https://cchain.explorer.avax.network/tx/",
    blockExplorerUrls: ["https://cchain.explorer.avax.network/"],
    rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
    defaultSymbol: {
      in: "AVAX",
      out: "USDT.e",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Avalanche",
      symbol: "AVAX",
    },
    disabled: false,
  },
  {
    chainName: "Polygon",
    chainCode: "polygon",
    chainId: 137,
    chainIcon: IconPolygon,
    txExplorerUrl: "https://polygonscan.com/tx/",
    blockExplorerUrls: ["https://polygonscan.com/"],
    rpcUrls: ["https://rpc-mainnet.maticvigil.com"],
    defaultSymbol: {
      in: "MATIC",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Matic",
      symbol: "MATIC",
    },
    disabled: false,
  },
  {
    chainName: "Fantom",
    chainCode: "fantom",
    chainId: 250,
    chainIcon: IconFantom,
    txExplorerUrl: "https://ftmscan.com/tx/",
    blockExplorerUrls: ["https://ftmscan.com/"],
    rpcUrls: ["https://rpcapi.fantom.network"],
    defaultSymbol: {
      in: "FTM",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Fantom",
      symbol: "FTM",
    },
    disabled: false,
  },
  {
    chainName: "Gnosis",
    chainCode: "xdai",
    chainId: 100,
    chainIcon: IconGnosis,
    txExplorerUrl: "https://blockscout.com/poa/xdai/tx/",
    blockExplorerUrls: ["https://blockscout.com/poa/xdai/"],
    rpcUrls: ["https://rpc.gnosischain.com"],
    defaultSymbol: {
      in: "XDAI",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "xDai",
      symbol: "xDai",
    },
    disabled: true,
  },
  {
    chainName: "Moonriver",
    chainCode: "moonriver",
    chainId: 1285,
    chainIcon: IconMoonriver,
    txExplorerUrl: "https://moonriver.moonscan.io/tx/",
    blockExplorerUrls: ["https://moonriver.moonscan.io/"],
    rpcUrls: ["https://rpc.moonriver.moonbeam.network"],
    defaultSymbol: {
      in: "MOVR",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Moonriver",
      symbol: "MOVR",
    },
    disabled: true,
  },
  {
    chainName: "Harmony",
    chainCode: "harmony",
    chainId: 1666600000,
    chainIcon: IconHarmony,
    txExplorerUrl: "https://explorer.harmony.one/tx/",
    blockExplorerUrls: ["https://explorer.harmony.one/"],
    rpcUrls: ["https://api.s0.t.hmny.io"],
    defaultSymbol: {
      in: "ONE",
      out: "1USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Harmony",
      symbol: "ONE",
    },
    disabled: true,
  },
  {
    chainName: "ZkSync",
    chainCode: "zksync",
    chainId: 324,
    chainIcon: IconZkSync,
    txExplorerUrl: "https://explorer.zksync.io/tx/",
    blockExplorerUrls: ["https://explorer.zksync.io/"],
    rpcUrls: ["https://mainnet.era.zksync.io"],
    defaultSymbol: {
      in: "ETH",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Ethereum",
      symbol: "ETH",
    },
    disabled: true,
  },
  {
    chainName: "Heco",
    chainCode: "heco",
    chainId: 128,
    chainIcon: IconHeco,
    txExplorerUrl: "https://hecoinfo.com/tx/",
    blockExplorerUrls: ["https://hecoinfo.com/"],
    rpcUrls: ["https://http-mainnet.hecochain.com"],
    defaultSymbol: {
      in: "HT",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Huobi Token",
      symbol: "HT",
    },
    disabled: true,
  },
  {
    chainName: "OKC",
    chainCode: "okex",
    chainId: 66,
    chainIcon: IconOKC,
    txExplorerUrl: "https://www.oklink.com/en/okc/tx/",
    blockExplorerUrls: ["https://www.oklink.com/en/okc/"],
    rpcUrls: ["https://exchainrpc.okex.org"],
    defaultSymbol: {
      in: "OKT",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "OKT",
      symbol: "OKT",
    },
    disabled: true,
  },
  {
    chainName: "Cronos",
    chainCode: "cronos",
    chainId: 25,
    chainIcon: IconCronos,
    txExplorerUrl: "https://cronos.org/explorer/tx/",
    blockExplorerUrls: ["https://cronos.org/explorer/"],
    rpcUrls: ["https://evm.cronos.org"],
    defaultSymbol: {
      in: "CRO",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Cronos",
      symbol: "CRO",
    },
    disabled: true,
  },
  {
    chainName: "Aurora",
    chainCode: "aurora",
    chainId: 1313161554,
    chainIcon: IconAurora,
    txExplorerUrl: "https://aurorascan.dev/tx/",
    blockExplorerUrls: ["https://aurorascan.dev/"],
    rpcUrls: ["https://mainnet.aurora.dev"],
    defaultSymbol: {
      in: "ETH",
      out: "USDC",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Ethereum",
      symbol: "ETH",
    },
    disabled: true,
  },
  {
    chainName: "Kava",
    chainCode: "kava",
    chainId: 2222,
    chainIcon: IconKava,
    txExplorerUrl: "https://explorer.kava.io/tx/",
    blockExplorerUrls: ["https://explorer.kava.io/"],
    rpcUrls: ["https://evm.kava.io"],
    defaultSymbol: {
      in: "KAVA",
      out: "USDT",
    },
    disabled: true,
  },
  {
    chainName: "Metis",
    chainCode: "metis",
    chainId: 1088,
    chainIcon: IconMetis,
    txExplorerUrl: "https://andromeda-explorer.metis.io/tx/",
    blockExplorerUrls: ["https://andromeda-explorer.metis.io/"],
    rpcUrls: ["https://andromeda.metis.io/?owner=1088"],
    defaultSymbol: {
      in: "METIS",
      out: "NETT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Metis",
      symbol: "METIS",
    },
    disabled: true,
  },
  {
    chainName: "Boba",
    chainCode: "boba",
    chainId: 288,
    chainIcon: IconBOBA,
    txExplorerUrl: "https://blockexplorer.boba.network/tx/",
    blockExplorerUrls: ["https://blockexplorer.boba.network/"],
    rpcUrls: ["https://mainnet.boba.network"],
    defaultSymbol: {
      in: "WETH",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Ethereum",
      symbol: "ETH",
    },
    disabled: true,
  },
  {
    chainName: "Celo",
    chainCode: "celo",
    chainId: 42220,
    chainIcon: IconCelo,
    txExplorerUrl: "https://explorer.celo.org/tx/",
    blockExplorerUrls: ["https://explorer.celo.org/"],
    rpcUrls: ["https://forno.celo.org"],
    defaultSymbol: {
      in: "CELO",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Celo",
      symbol: "CELO",
    },
    disabled: true,
  },
  {
    chainName: "Klaytn",
    chainCode: "klaytn",
    chainId: 8217,
    chainIcon: IconKlaytn,
    txExplorerUrl: "https://scope.klaytn.com/tx/",
    blockExplorerUrls: ["https://scope.klaytn.com/"],
    rpcUrls: ["https://public-node-api.klaytnapi.com/v1/cypress"],
    defaultSymbol: {
      in: "KLAY",
      out: "USDT",
    },
    nativeCurrency: {
      decimals: 18,
      name: "Klaytn",
      symbol: "KLAY",
    },
    disabled: true,
  },
];

export const getChainMap = () => {
  const map = {};
  ChainList.forEach(item => {
    map[item.chainId] = item;
  });
  return map;
}

export const getChainById = (chainId) => {
  return ChainList.find((item) => {
    return item.chainId === chainId;
  });
};

export const getChainByCode = (chainCode) => {
  return ChainList.find((item) => {
    return item.chainCode === chainCode;
  });
};

export const getChainCodeById = (chainId) => {
  const { chainCode } = ChainList.find((item) => {
    return item.chainId === chainId;
  });
  return chainCode;
};

export const getChainIdByCode = (chainCode) => {
  const { chainId } = ChainList.find((item) => {
    return item.chainCode === chainCode;
  });
  return chainId;
};

export const getAvailableChainList = () => {
  return ChainList.filter((item) => {
    return !item.disabled;
  });
};

export const getDefaultTokenByChain = (chainCode) => {
  const { chainId, defaultSymbol } = ChainList.find((item) => {
    return item.chainCode === chainCode;
  });
  const tokenList = TokenList[chainId] || [];
  const inToken = tokenList.find(item => {
    return item.symbol === defaultSymbol.in;
  });
  const outToken = tokenList.find(item => {
    return item.symbol === defaultSymbol.out;
  });
  return { inToken, outToken };
}
